package com.anquing.securitydemo.config;

/**
 * @author wangqq65
 * @since 2021/8/17 17:43
 */

import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

import static org.springframework.security.config.Customizer.withDefaults;

/**
 * Multiple HttpSecurity,order=1
 */
@Configuration
@Order(1)
public class ApiWebSecurityConfigurationAdapter extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                // 针对/api的接口，需要有ROLE_ADMIN角色
                .antMatcher("/api/**")
                .authorizeRequests(authorize -> authorize
                        .anyRequest().hasRole("ADMIN")
                )
//                    .httpBasic(withDefaults())
                .formLogin(withDefaults());
    }
}
